﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

/*
护盾
 */
public class Shield : Weapon {

	private float hp;
	private float defendPower;
	private float recoverHP;

	
	
	
	public GameObject gun;//装护盾的枪
	public GameObject target;//保护的目标
	public string Tag;//一开始的目标，为了避免隐身出现护盾，而护盾tag不更新而使用
	private float currHp;
	public bool isDefend = true;


	/// <summary>
	/// Awake is called when the script instance is being loaded.
	/// </summary>
	void Awake()
	{
		
	}

	// Use this for initialization
	void Start () {
		print("我是护盾");
		InitPro();
		SetPorByGrade(grade);
	}

	private void InitPro()
	{
		hp = 300;
		currHp = hp;
		defendPower = 0;
		recoverHP = 0;
		isDefend = true;
		if(gun != null)
		{
			gun.GetComponent<Gun>().isShow = isDefend;
		}
		
	}
	
	// Update is called once per frame
	void Update () {
		Recover();
		TagChange();
	}

	// 恢复血量
	public void Recover()
	{
		if(currHp < hp)
		{
			currHp += recoverHP;
		}
	}

	private void TagChange()
	{
		if(Tag != target.tag && Tag == "Untagged")
		{
			gameObject.tag = target.tag;
		}
	}


	// 计算伤害
	public void TakeDamage(float damage)
	{
		if(currHp <= 0)return;
		currHp -= damage;
		if(currHp <= 0)
		{
			isDefend = false;
			if(gun != null)
			{
				gun.GetComponent<Gun>().isShow = isDefend;
			}
			// target.tag = "Hero";
			print("护盾爆了");
			/*
			播放死亡动画
			*/
			Destroy(gameObject);
		}
		print("currHp--->" + currHp);
	}

	

	public void SetTarget(GameObject target)
	{
		this.target = target;
		this.transform.SetParent(target.transform);
		this.gameObject.tag = target.tag;
		this.Tag = target.tag;
		// this.target.tag = "Untagged";
	}

	public void SetGun(GameObject gun)
	{
		this.gun = gun;
	}


	void OnTriggerEnter2D(Collider2D other)
	{
		// print("currHp--->" + currHp);
	}


	// 设置等级初始化属性
	public void SetPorByGrade(string grade)
	{
		this.grade = grade;
		/*
		属性根据等级变化而变化
		 */
	}

	// 根据等级和星球类型设置星球属性
	public void SetGradeAndType(string grade, int shieleType)
	{
		this.grade = grade;
		
	}
}
